package com.bd.scm.module.synchronousAccount.controller;

import com.bd.scm.domain.models.synchronousAccount.ApiCreateAccount;
import com.bd.scm.domain.models.synchronousAccount.ApiRecyclingAccount;
import com.bd.scm.module.common.BaseController;
import com.bd.scm.module.synchronousAccount.service.SynchronousAccountService;
import com.bd.utils.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** 同步账号
 * Created with IntelliJ IDEA.
 * User: _Cps
 * Date: 2020.08.25 14:04
 */
@RestController
@RequestMapping("/api/synAccount")
public class SynchronousAccountController extends BaseController {

    @Autowired
    private SynchronousAccountService synchronousAccountService;

    /**
     * 创建账号 回收账号
     * @param apiCreateAccount
     * @return
     */
    @PostMapping("createAndRecyclingAccount")
    public HashMap<String,Object> createAndRecyclingAccount(@RequestBody ApiCreateAccount apiCreateAccount){
        HashMap<String,Object> res= new HashMap<>();
        try {
            String actionType = apiCreateAccount.getActionType();
            //创建账号
            if(actionType.equals("Add")){
                res.put("requestId",apiCreateAccount.getRequestId());
                res.put("returnFlag",true);
                res.put("returnCode","0");
                res.put("returnMessage","");
                List<HashMap<String, Object>> accountList = apiCreateAccount.getAccountList();
                ArrayList<HashMap> al = new ArrayList<>();
                for (Map<String, Object> map : accountList) {
                    HashMap<String,Object> ret= new HashMap<>();
                    ret.put("accountId",map.get("accountId"));
                    ret.put("accountCode","");
                    al.add(ret);
                }
                res.put("accountList",al);
            //回收账号
            }else if(actionType.equals("ReclaimAccount")){
                res.put("requestId",apiCreateAccount.getRequestId());
                res.put("returnFlag",true);
                res.put("returnCode","0");
                res.put("returnMessage","");
                List<String> accountList = this.synchronousAccountService.getUserIdList(Integer.valueOf(apiCreateAccount.getCurrentPage()));
                ArrayList<HashMap> al = new ArrayList<>();
                for (String map : accountList) {
                    HashMap<String,Object> ret= new HashMap<>();
                    ret.put("accountId",map);
                    ret.put("accountCode","");
                    ret.put("appCustomAttrs","");
                    al.add(ret);
                }
                res.put("accountList",al);
            }

            return res;
        } catch (Exception e) {
            e.printStackTrace();
            return res;
        }
    }


    /**
     * 回收账号
     * @param apiRecyclingAccount
     * @return
     */
//    @PostMapping("recyclingAccount")
//    public HashMap<String,Object> recyclingAccount(@RequestBody ApiRecyclingAccount apiRecyclingAccount){
//        HashMap<String,Object> res= new HashMap<>();
//        try {
//            res.put("requestId",apiRecyclingAccount.getRequestId());
//            res.put("returnFlag",true);
//            res.put("returnCode","0");
//            res.put("returnMessage","");
//            List<String> accountList = this.synchronousAccountService.getUserIdList(Integer.valueOf(apiRecyclingAccount.getCurrentPage()));
//            ArrayList<HashMap> al = new ArrayList<>();
//            for (String map : accountList) {
//                HashMap<String,Object> ret= new HashMap<>();
//                ret.put("accountId",map);
//                ret.put("accountCode","");
//                ret.put("appCustomAttrs","");
//                al.add(ret);
//            }
//            res.put("accountList",al);
//            return res;
//        } catch (Exception e) {
//            e.printStackTrace();
//            return res;
//        }
//    }

    @GetMapping("test")
    public Result test(){
        try {
//      第一步：登录获取token
//      第二步：获取下拉任务 第一步获取到的token
//      第三步：返回下拉完成信息给IDM
            //第一步得到的token
            //第二部得到的taskid
            //第二部的成功状态
            //第二部得到的guid
//      第四步：注销登录 	第一步得到的token
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.ok("Controller调用成功");
    }
}
